<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="language" content="en" />
        <link href="./assets/ffd55088/css/bootstrap.css" rel="stylesheet">
<link href="./assets/5cf9384a/solarized_light.css" rel="stylesheet">
<link href="./assets/6c54116e/style.css" rel="stylesheet">
<script src="./assets/a44cef0f/jquery.js"></script>
<script src="./assets/ffd55088/js/bootstrap.js"></script>
<script src="./assets/8ac4e28a/jssearch.js"></script>    <title>Url - Helpers - The Definitive Guide to Yii 2.0</title>
</head>
<body>

<div class="wrap">
    <nav id="w1631" class="navbar-inverse navbar-fixed-top navbar" role="navigation"><div class="navbar-header"><button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#w1631-collapse"><span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span></button><a class="navbar-brand" href="./index.html">The Definitive Guide to Yii 2.0</a></div><div id="w1631-collapse" class="collapse navbar-collapse"><ul id="w1632" class="navbar-nav nav"><li><a href="./index.html">Class reference</a></li>
<li class="dropdown"><a class="dropdown-toggle" href="#" data-toggle="dropdown">Extensions <b class="caret"></b></a><ul id="w1633" class="dropdown-menu"><li><a href="./ext-apidoc-index.html" tabindex="-1">apidoc</a></li>
<li><a href="./ext-authclient-index.html" tabindex="-1">authclient</a></li>
<li><a href="./ext-bootstrap-index.html" tabindex="-1">bootstrap</a></li>
<li><a href="./ext-codeception-index.html" tabindex="-1">codeception</a></li>
<li><a href="./ext-debug-index.html" tabindex="-1">debug</a></li>
<li><a href="./ext-elasticsearch-index.html" tabindex="-1">elasticsearch</a></li>
<li><a href="./ext-faker-index.html" tabindex="-1">faker</a></li>
<li><a href="./ext-gii-index.html" tabindex="-1">gii</a></li>
<li><a href="./ext-imagine-index.html" tabindex="-1">imagine</a></li>
<li><a href="./ext-jui-index.html" tabindex="-1">jui</a></li>
<li><a href="./ext-mongodb-index.html" tabindex="-1">mongodb</a></li>
<li><a href="./ext-redis-index.html" tabindex="-1">redis</a></li>
<li><a href="./ext-smarty-index.html" tabindex="-1">smarty</a></li>
<li><a href="./ext-sphinx-index.html" tabindex="-1">sphinx</a></li>
<li><a href="./ext-swiftmailer-index.html" tabindex="-1">swiftmailer</a></li>
<li><a href="./ext-twig-index.html" tabindex="-1">twig</a></li></ul></li>
<li><a href="./guide-README.html">Guide</a></li></ul><div class="navbar-form navbar-left" role="search">
  <div class="form-group">
    <input id="searchbox" type="text" class="form-control" placeholder="Search">
  </div>
</div>
</div></nav>
    <div id="search-resultbox" style="display: none;" class="modal-content">
        <ul id="search-results">
        </ul>
    </div>

    
<div class="row">
    <div class="col-md-2">
                <div id="navigation" class="list-group"><a class="list-group-item" href="#navigation-1615" data-toggle="collapse" data-parent="#navigation">Introduction <b class="caret"></b></a><div id="navigation-1615" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-intro-yii.html">About Yii</a>
<a class="list-group-item" href="./guide-intro-upgrade-from-v1.html">Upgrading from Version 1.1</a></div>
<a class="list-group-item" href="#navigation-1616" data-toggle="collapse" data-parent="#navigation">Getting Started <b class="caret"></b></a><div id="navigation-1616" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-start-installation.html">Installing Yii</a>
<a class="list-group-item" href="./guide-start-workflow.html">Running Applications</a>
<a class="list-group-item" href="./guide-start-hello.html">Saying Hello</a>
<a class="list-group-item" href="./guide-start-forms.html">Working with Forms</a>
<a class="list-group-item" href="./guide-start-databases.html">Working with Databases</a>
<a class="list-group-item" href="./guide-start-gii.html">Generating Code with Gii</a>
<a class="list-group-item" href="./guide-start-looking-ahead.html">Looking Ahead</a></div>
<a class="list-group-item" href="#navigation-1617" data-toggle="collapse" data-parent="#navigation">Application Structure <b class="caret"></b></a><div id="navigation-1617" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-structure-overview.html">Overview</a>
<a class="list-group-item" href="./guide-structure-entry-scripts.html">Entry Scripts</a>
<a class="list-group-item" href="./guide-structure-applications.html">Applications</a>
<a class="list-group-item" href="./guide-structure-application-components.html">Application Components</a>
<a class="list-group-item" href="./guide-structure-controllers.html">Controllers</a>
<a class="list-group-item" href="./guide-structure-models.html">Models</a>
<a class="list-group-item" href="./guide-structure-views.html">Views</a>
<a class="list-group-item" href="./guide-structure-modules.html">Modules</a>
<a class="list-group-item" href="./guide-structure-filters.html">Filters</a>
<a class="list-group-item" href="./guide-structure-widgets.html">Widgets</a>
<a class="list-group-item" href="./guide-structure-assets.html">Assets</a>
<a class="list-group-item" href="./guide-structure-extensions.html">Extensions</a></div>
<a class="list-group-item" href="#navigation-1618" data-toggle="collapse" data-parent="#navigation">Handling Requests <b class="caret"></b></a><div id="navigation-1618" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-runtime-overview.html">Overview</a>
<a class="list-group-item" href="./guide-runtime-bootstrapping.html">Bootstrapping</a>
<a class="list-group-item" href="./guide-runtime-routing.html">Routing and URL Creation</a>
<a class="list-group-item" href="./guide-runtime-requests.html">Requests</a>
<a class="list-group-item" href="./guide-runtime-responses.html">Responses</a>
<a class="list-group-item" href="./guide-runtime-sessions-cookies.html">Sessions and Cookies</a>
<a class="list-group-item" href="./guide-runtime-handling-errors.html">Handling Errors</a>
<a class="list-group-item" href="./guide-runtime-logging.html">Logging</a></div>
<a class="list-group-item" href="#navigation-1619" data-toggle="collapse" data-parent="#navigation">Key Concepts <b class="caret"></b></a><div id="navigation-1619" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-concept-components.html">Components</a>
<a class="list-group-item" href="./guide-concept-properties.html">Properties</a>
<a class="list-group-item" href="./guide-concept-events.html">Events</a>
<a class="list-group-item" href="./guide-concept-behaviors.html">Behaviors</a>
<a class="list-group-item" href="./guide-concept-configurations.html">Configurations</a>
<a class="list-group-item" href="./guide-concept-aliases.html">Aliases</a>
<a class="list-group-item" href="./guide-concept-autoloading.html">Class Autoloading</a>
<a class="list-group-item" href="./guide-concept-service-locator.html">Service Locator</a>
<a class="list-group-item" href="./guide-concept-di-container.html">Dependency Injection Container</a></div>
<a class="list-group-item" href="#navigation-1620" data-toggle="collapse" data-parent="#navigation">Working with Databases <b class="caret"></b></a><div id="navigation-1620" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-db-dao.html">Data Access Objects</a>
<a class="list-group-item" href="./guide-db-query-builder.html">Query Builder</a>
<a class="list-group-item" href="./guide-db-active-record.html">Active Record</a>
<a class="list-group-item" href="./guide-db-migrations.html">Migrations</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-sphinx/blob/master/docs/guide/README.md">Sphinx</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-redis/blob/master/docs/guide/README.md">Redis</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-mongodb/blob/master/docs/guide/README.md">MongoDB</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-elasticsearch/blob/master/docs/guide/README.md">ElasticSearch</a></div>
<a class="list-group-item" href="#navigation-1621" data-toggle="collapse" data-parent="#navigation">Getting Data from Users <b class="caret"></b></a><div id="navigation-1621" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-input-forms.html">Creating Forms</a>
<a class="list-group-item" href="./guide-input-validation.html">Validating Input</a>
<a class="list-group-item" href="./guide-input-file-upload.html">Uploading Files</a>
<a class="list-group-item" href="./guide-input-tabular-input.html">Collecting Tabular Input</a>
<a class="list-group-item" href="./guide-input-multiple-models.html">Getting Data for Multiple Models</a></div>
<a class="list-group-item" href="#navigation-1622" data-toggle="collapse" data-parent="#navigation">Displaying Data <b class="caret"></b></a><div id="navigation-1622" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-output-formatting.html">Data Formatting</a>
<a class="list-group-item" href="./guide-output-pagination.html">Pagination</a>
<a class="list-group-item" href="./guide-output-sorting.html">Sorting</a>
<a class="list-group-item" href="./guide-output-data-providers.html">Data Providers</a>
<a class="list-group-item" href="./guide-output-data-widgets.html">Data Widgets</a>
<a class="list-group-item" href="./guide-output-client-scripts.html">Working with Client Scripts</a>
<a class="list-group-item" href="./guide-output-theming.html">Theming</a></div>
<a class="list-group-item" href="#navigation-1623" data-toggle="collapse" data-parent="#navigation">Security <b class="caret"></b></a><div id="navigation-1623" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-security-overview.html">Overview</a>
<a class="list-group-item" href="./guide-security-authentication.html">Authentication</a>
<a class="list-group-item" href="./guide-security-authorization.html">Authorization</a>
<a class="list-group-item" href="./guide-security-passwords.html">Working with Passwords</a>
<a class="list-group-item" href="./guide-security-cryptography.html">Cryptography</a>
<a class="list-group-item" href="./guide-structure-views.html#security">Views security</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-authclient/blob/master/docs/guide/README.md">Auth Clients</a>
<a class="list-group-item" href="./guide-security-best-practices.html">Best Practices</a></div>
<a class="list-group-item" href="#navigation-1624" data-toggle="collapse" data-parent="#navigation">Caching <b class="caret"></b></a><div id="navigation-1624" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-caching-overview.html">Overview</a>
<a class="list-group-item" href="./guide-caching-data.html">Data Caching</a>
<a class="list-group-item" href="./guide-caching-fragment.html">Fragment Caching</a>
<a class="list-group-item" href="./guide-caching-page.html">Page Caching</a>
<a class="list-group-item" href="./guide-caching-http.html">HTTP Caching</a></div>
<a class="list-group-item" href="#navigation-1625" data-toggle="collapse" data-parent="#navigation">RESTful Web Services <b class="caret"></b></a><div id="navigation-1625" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-rest-quick-start.html">Quick Start</a>
<a class="list-group-item" href="./guide-rest-resources.html">Resources</a>
<a class="list-group-item" href="./guide-rest-controllers.html">Controllers</a>
<a class="list-group-item" href="./guide-rest-routing.html">Routing</a>
<a class="list-group-item" href="./guide-rest-response-formatting.html">Response Formatting</a>
<a class="list-group-item" href="./guide-rest-authentication.html">Authentication</a>
<a class="list-group-item" href="./guide-rest-rate-limiting.html">Rate Limiting</a>
<a class="list-group-item" href="./guide-rest-versioning.html">Versioning</a>
<a class="list-group-item" href="./guide-rest-error-handling.html">Error Handling</a></div>
<a class="list-group-item" href="#navigation-1626" data-toggle="collapse" data-parent="#navigation">Development Tools <b class="caret"></b></a><div id="navigation-1626" class="submenu panel-collapse collapse"><a class="list-group-item" href="https://github.com/yiisoft/yii2-debug/blob/master/docs/guide/README.md">Debug Toolbar and Debugger</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-gii/blob/master/docs/guide/README.md">Generating Code using Gii</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-apidoc">Generating API Documentation</a></div>
<a class="list-group-item" href="#navigation-1627" data-toggle="collapse" data-parent="#navigation">Testing <b class="caret"></b></a><div id="navigation-1627" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-test-overview.html">Overview</a>
<a class="list-group-item" href="./guide-test-environment-setup.html">Testing environment setup</a>
<a class="list-group-item" href="./guide-test-unit.html">Unit Tests</a>
<a class="list-group-item" href="./guide-test-functional.html">Functional Tests</a>
<a class="list-group-item" href="./guide-test-acceptance.html">Acceptance Tests</a>
<a class="list-group-item" href="./guide-test-fixtures.html">Fixtures</a></div>
<a class="list-group-item" href="#navigation-1628" data-toggle="collapse" data-parent="#navigation">Special Topics <b class="caret"></b></a><div id="navigation-1628" class="submenu panel-collapse collapse"><a class="list-group-item" href="https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/README.md">Advanced Project Template</a>
<a class="list-group-item" href="./guide-tutorial-start-from-scratch.html">Building Application from Scratch</a>
<a class="list-group-item" href="./guide-tutorial-console.html">Console Commands</a>
<a class="list-group-item" href="./guide-tutorial-core-validators.html">Core Validators</a>
<a class="list-group-item" href="./guide-tutorial-i18n.html">Internationalization</a>
<a class="list-group-item" href="./guide-tutorial-mailing.html">Mailing</a>
<a class="list-group-item" href="./guide-tutorial-performance-tuning.html">Performance Tuning</a>
<a class="list-group-item" href="./guide-tutorial-shared-hosting.html">Shared Hosting Environment</a>
<a class="list-group-item" href="./guide-tutorial-template-engines.html">Template Engines</a>
<a class="list-group-item" href="./guide-tutorial-yii-integration.html">Working with Third-Party Code</a></div>
<a class="list-group-item" href="#navigation-1629" data-toggle="collapse" data-parent="#navigation">Widgets <b class="caret"></b></a><div id="navigation-1629" class="submenu panel-collapse collapse"><a class="list-group-item" href="https://github.com/yiisoft/yii2-bootstrap/blob/master/docs/guide/README.md">Bootstrap Widgets</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-jui/blob/master/docs/guide/README.md">jQuery UI Widgets</a></div>
<a class="list-group-item active" href="#navigation-1630" data-toggle="collapse" data-parent="#navigation">Helpers <b class="caret"></b></a><div id="navigation-1630" class="submenu panel-collapse collapse in"><a class="list-group-item" href="./guide-helper-overview.html">Overview</a>
<a class="list-group-item" href="./guide-helper-array.html">ArrayHelper</a>
<a class="list-group-item" href="./guide-helper-html.html">Html</a>
<a class="list-group-item active" href="./guide-helper-url.html">Url</a></div></div>    </div>
    <div class="col-md-9 guide-content" role="main">
        <h1>Url Helper <span id="url-helper"></span><a href="#url-helper" class="hashlink">&para;</a></h1>
<div class="toc"><ol><li><a href="#getting-common-urls">Getting Common URLs</a></li>
<li><a href="#creating-urls">Creating URLs</a></li>
<li><a href="#remember-urls">Remember URLs</a></li>
<li><a href="#checking-relative-urls">Checking Relative URLs</a></li></ol></div>
<p>Url helper provides a set of static methods for managing URLs.</p>
<h2>Getting Common URLs  <span id="getting-common-urls"></span><a href="#getting-common-urls" class="hashlink">&para;</a></h2><p>There are two methods you can use to get common URLs: home URL and base URL of the current request. In order to get
home URL, use the following:</p>
<pre><code class="hljs php language-php"><span class="hljs-variable">$relativeHomeUrl</span> = Url::home();
<span class="hljs-variable">$absoluteHomeUrl</span> = Url::home(<span class="hljs-keyword">true</span>);
<span class="hljs-variable">$httpsAbsoluteHomeUrl</span> = Url::home(<span class="hljs-string">'https'</span>);
</code></pre>
<p>If no parameter is passed, the generated URL is relative. You can either pass <code>true</code> to get an absolute URL for the current
schema or specify a schema explicitly (<code>https</code>, <code>http</code>).</p>
<p>To get the base URL of the current request use the following:</p>
<pre><code class="hljs php language-php"><span class="hljs-variable">$relativeBaseUrl</span> = Url::base();
<span class="hljs-variable">$absoluteBaseUrl</span> = Url::base(<span class="hljs-keyword">true</span>);
<span class="hljs-variable">$httpsAbsoluteBaseUrl</span> = Url::base(<span class="hljs-string">'https'</span>);
</code></pre>
<p>The only parameter of the method works exactly the same as for <code>Url::home()</code>.</p>
<h2>Creating URLs  <span id="creating-urls"></span><a href="#creating-urls" class="hashlink">&para;</a></h2><p>In order to create a URL to a given route use the <code>Url::toRoute()</code> method. The method uses <a href="./yii-web-urlmanager.html">yii\web\UrlManager</a> to create
a URL:</p>
<pre><code class="hljs php language-php"><span class="hljs-variable">$url</span> = Url::toRoute([<span class="hljs-string">'product/view'</span>, <span class="hljs-string">'id'</span> =&gt; <span class="hljs-number">42</span>]);
</code></pre>
<p>You may specify the route as a string, e.g., <code>site/index</code>. You may also use an array if you want to specify additional
query parameters for the URL being created. The array format must be:</p>
<pre><code class="hljs php language-php"><span class="hljs-comment">// generates: /index.php?r=site%2Findex&amp;param1=value1&amp;param2=value2</span>
[<span class="hljs-string">'site/index'</span>, <span class="hljs-string">'param1'</span> =&gt; <span class="hljs-string">'value1'</span>, <span class="hljs-string">'param2'</span> =&gt; <span class="hljs-string">'value2'</span>]
</code></pre>
<p>If you want to create a URL with an anchor, you can use the array format with a <code>#</code> parameter. For example,</p>
<pre><code class="hljs php language-php"><span class="hljs-comment">// generates: /index.php?r=site%2Findex&amp;param1=value1#name</span>
[<span class="hljs-string">'site/index'</span>, <span class="hljs-string">'param1'</span> =&gt; <span class="hljs-string">'value1'</span>, <span class="hljs-string">'#'</span> =&gt; <span class="hljs-string">'name'</span>]
</code></pre>
<p>A route may be either absolute or relative. An absolute route has a leading slash (e.g. <code>/site/index</code>) while a relative
route has none (e.g. <code>site/index</code> or <code>index</code>). A relative route will be converted into an absolute one by the following rules:</p>
<ul>
<li>If the route is an empty string, the current <a href="./yii-base-controller.html#$route-detail">route</a> will be used;</li>
<li>If the route contains no slashes at all (e.g. <code>index</code>), it is considered to be an action ID of the current controller
and will be prepended with <a href="./yii-base-controller.html#$uniqueId-detail">yii\web\Controller::$uniqueId</a>;</li>
<li>If the route has no leading slash (e.g. <code>site/index</code>), it is considered to be a route relative to the current module
and will be prepended with the module's <a href="./yii-base-module.html#$uniqueId-detail">uniqueId</a>.</li>
</ul>
<p>Starting from version 2.0.2, you may specify a route in terms of an <a href="guide-concept-aliases.html">alias</a>. If this is the case,
the alias will first be converted into the actual route which will then be turned into an absolute route according
to the above rules.</p>
<p>Below are some examples of using this method:</p>
<pre><code class="hljs php language-php"><span class="hljs-comment">// /index.php?r=site%2Findex</span>
<span class="hljs-keyword">echo</span> Url::toRoute(<span class="hljs-string">'site/index'</span>);

<span class="hljs-comment">// /index.php?r=site%2Findex&amp;src=ref1#name</span>
<span class="hljs-keyword">echo</span> Url::toRoute([<span class="hljs-string">'site/index'</span>, <span class="hljs-string">'src'</span> =&gt; <span class="hljs-string">'ref1'</span>, <span class="hljs-string">'#'</span> =&gt; <span class="hljs-string">'name'</span>]);

<span class="hljs-comment">// /index.php?r=post%2Fedit&amp;id=100     assume the alias "@postEdit" is defined as "post/edit"</span>
<span class="hljs-keyword">echo</span> Url::toRoute([<span class="hljs-string">'@postEdit'</span>, <span class="hljs-string">'id'</span> =&gt; <span class="hljs-number">100</span>]);

<span class="hljs-comment">// http://www.example.com/index.php?r=site%2Findex</span>
<span class="hljs-keyword">echo</span> Url::toRoute(<span class="hljs-string">'site/index'</span>, <span class="hljs-keyword">true</span>);

<span class="hljs-comment">// https://www.example.com/index.php?r=site%2Findex</span>
<span class="hljs-keyword">echo</span> Url::toRoute(<span class="hljs-string">'site/index'</span>, <span class="hljs-string">'https'</span>);
</code></pre>
<p>There's another method <code>Url::to()</code> that is very similar to <span class="broken-link">toRoute()</span>. The only difference is that this method
requires a route to be specified as an array only. If a string is given, it will be treated as a URL.</p>
<p>The first argument could be:</p>
<ul>
<li>an array: <span class="broken-link">toRoute()</span> will be called to generate the URL. For example:
<code>['site/index']</code>, <code>['post/index', 'page' =&gt; 2]</code>. Please refer to <span class="broken-link">toRoute()</span> for more details
on how to specify a route.</li>
<li>a string with a leading <code>@</code>: it is treated as an alias, and the corresponding aliased string
will be returned.</li>
<li>an empty string: the currently requested URL will be returned;</li>
<li>a normal string: it will be returned as is.</li>
</ul>
<p>When <code>$scheme</code> is specified (either a string or true), an absolute URL with host info (obtained from
<a href="./yii-web-urlmanager.html#$hostInfo-detail">yii\web\UrlManager::$hostInfo</a>) will be returned. If <code>$url</code> is already an absolute URL, its scheme
will be replaced with the specified one.</p>
<p>Below are some usage examples:</p>
<pre><code class="hljs php language-php"><span class="hljs-comment">// /index.php?r=site%2Findex</span>
<span class="hljs-keyword">echo</span> Url::to([<span class="hljs-string">'site/index'</span>]);

<span class="hljs-comment">// /index.php?r=site%2Findex&amp;src=ref1#name</span>
<span class="hljs-keyword">echo</span> Url::to([<span class="hljs-string">'site/index'</span>, <span class="hljs-string">'src'</span> =&gt; <span class="hljs-string">'ref1'</span>, <span class="hljs-string">'#'</span> =&gt; <span class="hljs-string">'name'</span>]);

<span class="hljs-comment">// /index.php?r=post%2Fedit&amp;id=100     assume the alias "@postEdit" is defined as "post/edit"</span>
<span class="hljs-keyword">echo</span> Url::to([<span class="hljs-string">'@postEdit'</span>, <span class="hljs-string">'id'</span> =&gt; <span class="hljs-number">100</span>]);

<span class="hljs-comment">// the currently requested URL</span>
<span class="hljs-keyword">echo</span> Url::to();

<span class="hljs-comment">// /images/logo.gif</span>
<span class="hljs-keyword">echo</span> Url::to(<span class="hljs-string">'@web/images/logo.gif'</span>);

<span class="hljs-comment">// images/logo.gif</span>
<span class="hljs-keyword">echo</span> Url::to(<span class="hljs-string">'images/logo.gif'</span>);

<span class="hljs-comment">// http://www.example.com/images/logo.gif</span>
<span class="hljs-keyword">echo</span> Url::to(<span class="hljs-string">'@web/images/logo.gif'</span>, <span class="hljs-keyword">true</span>);

<span class="hljs-comment">// https://www.example.com/images/logo.gif</span>
<span class="hljs-keyword">echo</span> Url::to(<span class="hljs-string">'@web/images/logo.gif'</span>, <span class="hljs-string">'https'</span>);
</code></pre>
<p>Starting from version 2.0.3, you may use <a href="./yii-helpers-baseurl.html#current()-detail">yii\helpers\Url::current()</a> to create a URL based on the currently
requested route and GET parameters. You may modify or remove some of the GET parameters or add new ones by
passing a <code>$params</code> parameter to the method. For example,</p>
<pre><code class="hljs php language-php"><span class="hljs-comment">// assume $_GET = ['id' =&gt; 123, 'src' =&gt; 'google'], current route is "post/view"</span>

<span class="hljs-comment">// /index.php?r=post%2Fview&amp;id=123&amp;src=google</span>
<span class="hljs-keyword">echo</span> Url::current();

<span class="hljs-comment">// /index.php?r=post%2Fview&amp;id=123</span>
<span class="hljs-keyword">echo</span> Url::current([<span class="hljs-string">'src'</span> =&gt; <span class="hljs-keyword">null</span>]);
<span class="hljs-comment">// /index.php?r=post%2Fview&amp;id=100&amp;src=google</span>
<span class="hljs-keyword">echo</span> Url::current([<span class="hljs-string">'id'</span> =&gt; <span class="hljs-number">100</span>]);
</code></pre>
<h2>Remember URLs  <span id="remember-urls"></span><a href="#remember-urls" class="hashlink">&para;</a></h2><p>There are cases when you need to remember URL and afterwards use it during processing of the one of sequential requests.
It can be achieved in the following way:</p>
<pre><code class="hljs php language-php"><span class="hljs-comment">// Remember current URL </span>
Url::remember();

<span class="hljs-comment">// Remember URL specified. See Url::to() for argument format.</span>
Url::remember([<span class="hljs-string">'product/view'</span>, <span class="hljs-string">'id'</span> =&gt; <span class="hljs-number">42</span>]);

<span class="hljs-comment">// Remember URL specified with a name given</span>
Url::remember([<span class="hljs-string">'product/view'</span>, <span class="hljs-string">'id'</span> =&gt; <span class="hljs-number">42</span>], <span class="hljs-string">'product'</span>);
</code></pre>
<p>In the next request we can get URL remembered in the following way:</p>
<pre><code class="hljs php language-php"><span class="hljs-variable">$url</span> = Url::previous();
<span class="hljs-variable">$productUrl</span> = Url::previous(<span class="hljs-string">'product'</span>);
</code></pre>
<h2>Checking Relative URLs  <span id="checking-relative-urls"></span><a href="#checking-relative-urls" class="hashlink">&para;</a></h2><p>To find out if URL is relative i.e. it doesn't have host info part, you can use the following code:</p>
<pre><code class="hljs php language-php"><span class="hljs-variable">$isRelative</span> = Url::isRelative(<span class="hljs-string">'test/it'</span>);
</code></pre>
        <div class="toplink"><a href="#" class="h1" title="go to top"><span class="glyphicon glyphicon-arrow-up"></a></div>
    </div>
</div>


</div>

<footer class="footer">
        <p class="pull-right"><small>Page generated on Sat, 09 Jul 2016 12:16:31 +0000</small></p>
    Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a></footer>

<script type="text/javascript">jQuery(document).ready(function () {
    var shiftWindow = function () { scrollBy(0, -50) };
    if (location.hash) setTimeout(shiftWindow, 1);
    window.addEventListener("hashchange", shiftWindow);
var element = document.createElement("script");
element.src = "./jssearch.index.js";
document.body.appendChild(element);

var searchBox = $('#searchbox');

// search when typing in search field
searchBox.on("keyup", function(event) {
    var query = $(this).val();

    if (query == '' || event.which == 27) {
        $('#search-resultbox').hide();
        return;
    } else if (event.which == 13) {
        var selectedLink = $('#search-resultbox a.selected');
        if (selectedLink.length != 0) {
            document.location = selectedLink.attr('href');
            return;
        }
    } else if (event.which == 38 || event.which == 40) {
        $('#search-resultbox').show();

        var selected = $('#search-resultbox a.selected');
        if (selected.length == 0) {
            $('#search-results').find('a').first().addClass('selected');
        } else {
            var next;
            if (event.which == 40) {
                next = selected.parent().next().find('a').first();
            } else {
                next = selected.parent().prev().find('a').first();
            }
            if (next.length != 0) {
                var resultbox = $('#search-results');
                var position = next.position();

//              TODO scrolling is buggy and jumps around
//                resultbox.scrollTop(Math.floor(position.top));
//                console.log(position.top);

                selected.removeClass('selected');
                next.addClass('selected');
            }
        }

        return;
    }
    $('#search-resultbox').show();
    $('#search-results').html('<li><span class="no-results">No results</span></li>');

    var result = jssearch.search(query);

    if (result.length > 0) {
        var i = 0;
        var resHtml = '';

        for (var key in result) {
            if (i++ > 20) {
                break;
            }
            resHtml = resHtml +
            '<li><a href="' + result[key].file.u.substr(3) +'"><span class="title">' + result[key].file.t + '</span>' +
            '<span class="description">' + result[key].file.d + '</span></a></li>';
        }
        $('#search-results').html(resHtml);
    }
});

// hide the search results on ESC
$(document).on("keyup", function(event) { if (event.which == 27) { $('#search-resultbox').hide(); } });
// hide search results on click to document
$(document).bind('click', function (e) { $('#search-resultbox').hide(); });
// except the following:
searchBox.bind('click', function(e) { e.stopPropagation(); });
$('#search-resultbox').bind('click', function(e) { e.stopPropagation(); });

});</script></body>
</html>
